<?php

class CommodityRequireComment
{
    /** @var int */
    protected $id = 0;
    /** @var string */
    protected $content = '';
    /** @var int */
    protected $private = 0;
    /** @var int */
    protected $releaseTime = null;
    /** @var int */
    protected $fatherId = 0;
    /** @var int */
    protected $userId = 0;
    /** @var int */
    protected $commodityRequireId = 0;
    /** @var int */
    protected $toUserId = 0;
    /** @var int */
    protected $masterUserId = 0;

    public function isPrivate()
    {
        if ($this->getPrivate() > 0) {
            return true;
        } else {
            return false;
        }
    }

    public function isDeleted()
    {
        if ($this->getPrivate() >= 100) {
            return true;
        } else {
            return false;
        }
    }

    public function setDeletedFlag()
    {
        if ($this->getPrivate() < 100) {
            $this->setPrivate($this->getPrivate() + 100);
        }
    }

    public function getLinkDisplayTitle()
    {
        $commodityRequire = CommodityRequire_Model::getCommodityRequireById($this->getCommodityRequireId());
        if (!$commodityRequire) return '[未知标题]';
        return $commodityRequire->getTitle();
    }

    public function getUserDisplayName()
    {
        return User_Model::getUserById($this->getUserId())->getDisplayName();
    }

    public function getCommodityRequireUserId()
    {
        if ($this->getCommodityRequireId() && $this->getCommodityRequireId() > 0) {
            $thatCommodity = Commodity_Model::getCommodityById($this->getCommodityRequireId());
            if ($thatCommodity && $thatCommodity->getUserId() > 0)
                return $this->userId;
            return 0;
        }
        return 0;
    }

    public function getAvatarUrl()
    {
        return User_Model::getUserById($this->getUserId())->getDisplayAvatarUrl();
    }

    public function getToUser()
    {
        $toUser = User_Model::getUserById($this->getToUserId());
        if (!$toUser) return null;
        return $toUser;
    }

    public function getMasterUser()
    {
        $masterUser = User_Model::getUserById($this->getMasterUserId());
        if (!$masterUser) return null;
        return $masterUser;
    }

    public function getFatherComment()
    {
        if (!$this->getFatherId()) return null;
        $father = CommodityRequireComment_Model::getCommodityRequireCommentById($this->getFatherId());
        if (!$father) return null;
        return $father;
    }

    public function getUser()
    {
        $user = User_Model::getUserById($this->getUserId());
        if (!$user) return null;
        return $user;
    }

    /**
     * @return array
     */
    public function getDataArray()
    {
        return array(
            'id'                 => $this->getId(),
            'userId'             => $this->getUserId(),
            'userDisplayName'    => $this->getUserDisplayName(),
            'userAvatarUrl'      => $this->getAvatarUrl(),
            'content'            => $this->getContent(),
            'private'            => $this->getPrivate(),
            'releaseTime'        => $this->getReleaseTime(),
            'fatherId'           => $this->getFatherId(),
            'commodityRequireId' => $this->getCommodityRequireId(),
            'to_user_id'      => $this->getToUserId(),
            'master_user_id'  => $this->getMasterUserId(),
        );
    }

    /**
     * @return array
     */
    public function getDataArrayAsPrivate()
    {
        return array(
            'id'                 => $this->getId(),
            'userId'             => 0,
            'userDisplayName'    => '[匿名]',
            'userAvatarUrl'      => base_url('public/images/default.gif'),
            'content'            => '[密谈]',
            'private'            => $this->getPrivate(),
            'releaseTime'        => $this->getReleaseTime(),
            'fatherId'           => $this->getFatherId(),
            'commodityRequireId' => $this->getCommodityRequireId(),
            'to_user_id'      => $this->getToUserId(),
            'master_user_id'  => $this->getMasterUserId(),
        );
    }

    /**
     * @return array
     */
    public function getDataArrayAsDeleted()
    {
        return array(
            'id'                 => $this->getId(),
            'userId'             => 0,
            'userDisplayName'    => '[匿名]',
            'userAvatarUrl'      => base_url('public/images/default.gif'),
            'content'            => '[此留言已被删除]',
            'private'            => $this->getPrivate(),
            'releaseTime'        => $this->getReleaseTime(),
            'fatherId'           => $this->getFatherId(),
            'commodityRequireId' => $this->getCommodityRequireId(),
            'to_user_id'      => $this->getToUserId(),
            'master_user_id'  => $this->getMasterUserId(),
        );
    }

    /**
     * @return int
     */
    public function getCommodityRequireId()
    {
        return $this->commodityRequireId;
    }

    /**
     * @param int $commodityRequireId
     */
    public function setCommodityRequireId($commodityRequireId)
    {
        $this->commodityRequireId = $commodityRequireId;
    }

    /**
     * @return string
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * @param string $content
     */
    public function setContent($content)
    {
        $this->content = $content;
    }

    /**
     * @return int
     */
    public function getFatherId()
    {
        return $this->fatherId;
    }

    /**
     * @param int $fatherId
     */
    public function setFatherId($fatherId)
    {
        $this->fatherId = $fatherId;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return int
     */
    public function getPrivate()
    {
        return $this->private;
    }

    /**
     * @param int $private
     */
    public function setPrivate($private)
    {
        $this->private = $private;
    }

    /**
     * @return int
     */
    public function getReleaseTime()
    {
        return $this->releaseTime;
    }

    /**
     * @param int $releaseTime
     */
    public function setReleaseTime($releaseTime)
    {
        $this->releaseTime = $releaseTime;
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * @param int $userId
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    /**
     * @return int
     */
    public function getMasterUserId()
    {
        return $this->masterUserId;
    }

    /**
     * @param int $masterUserId
     */
    public function setMasterUserId($masterUserId)
    {
        $this->masterUserId = $masterUserId;
    }

    /**
     * @return int
     */
    public function getToUserId()
    {
        return $this->toUserId;
    }

    /**
     * @param int $toUserId
     */
    public function setToUserId($toUserId)
    {
        $this->toUserId = $toUserId;
    }


}